package com.Smart.smartscals.DataBase;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class SqliteDataHelper extends SQLiteOpenHelper {
	private static final String DBName = "WEIGHT.DB";
	private static final int version = 1;
	public static final String TB_USERINFO = "UserInfo"; 
	public static final String TB_BODYFAT = "BodyInfo";
	public static final String TB_LOADTIME = "loadTimeInfo";

	public static final String USERID = "uid";
	public static final String NAME ="userName";
	public static final String PWD ="passWord"; 
	public static final String BIRTHDAY ="birthday";
	public static final String SEX = "userSex";
	public static final String HEIGHT = "userHeight";

	//用户数据表参数
	public static final String ID = "_id";  
	public static final String DATE = "date"; 
	public static final String BODY_WEIGHT = "weight";
	public static final String BODY_FAT = "bodyFat";
	public static final String WEEK_NUM ="weekNUM";
	public static final String MONTH_NUM ="monthNUM";
	public static final String DAY_NUM ="dayNUM";
	public static final String YEAR_NUM ="yearNUM";

	//下载时间表
	public static final String LoadDownID = "_loadId";
	public static final String LoadDownTime = "loadTime";

	public SqliteDataHelper(Context context) {
		super(context, DBName, null, version);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		//创建用户信息表
		db.execSQL("CREATE TABLE IF NOT EXISTS "   
				+ TB_USERINFO + " ("   
				+ USERID + " INTEGER PRIMARY KEY AUTOINCREMENT ,"           
				+ NAME+ " TEXT,"
				+ PWD+ " TEXT,"
				+ BIRTHDAY + " TEXT,"   
				+ SEX + " TEXT,"             
				+ HEIGHT + " TEXT);");  

		//创建用户数据表  
		db.execSQL("CREATE TABLE IF NOT EXISTS "   
				+ TB_BODYFAT + " ("   
				+ ID + " INTEGER PRIMARY KEY AUTOINCREMENT ,"   
				+ DATE + " INTEGER,"  
				+ BODY_WEIGHT + " VARCHAR,"
				+ BODY_FAT + " VARCHAR,"        
				+ WEEK_NUM + " VARCHAR,"    
				+ MONTH_NUM + " VARCHAR,"    
				+ DAY_NUM + " VARCHAR,"  
				+ YEAR_NUM+ " VARCHAR,"
				+ NAME + " TEXT)");  
		//创建下载时间表
		db.execSQL("CREATE TABLE IF NOT EXISTS "   
				+ TB_LOADTIME + " ("   
				+ LoadDownID + " INTEGER PRIMARY KEY AUTOINCREMENT ,"   
				+ NAME+ " TEXT,"
				+ LoadDownTime + " TEXT);");  
		Log.i("blackk22", "三个表创建完毕");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS "+TB_USERINFO);  
		db.execSQL("DROP TABLE IF EXISTS "+TB_BODYFAT);   
		db.execSQL("DROP TABLE IF EXISTS "+TB_LOADTIME);
		onCreate(db); 

	}



}
